# -*- coding: utf-8 -*

def listBase():
    integer_list = [1, 2, 3]
    heterogeneous_list = ["string", 0.1, True]
    list_of_lists = [integer_list, heterogeneous_list, []]
    list_length = len(integer_list)  # equals 3
    list_sum = sum(integer_list)  # equals 6
    print list_length, list_sum


def nth():
    x = range(10)  # is the list [0, 1, ..., 9]
    zero = x[0]  # equals 0, lists are 0-indexed
    one = x[1]  # equals 1
    nine = x[-1]  # equals 9, 'Pythonic' for last element
    eight = x[-2]  # equals 8, 'Pythonic' for next-to-last element
    x[0] = -1  # now x is [-1, 1, 2, 3, ..., 9]
    print nine, eight


def slice():
    x = range(10)  # is the list [0, 1, ..., 9]
    first_three = x[:3]  # [-1, 1, 2]
    three_to_end = x[3:]  # [3, 4, ..., 9]
    one_to_four = x[1:5]  # [1, 2, 3, 4]
    last_three = x[-3:]  # [7, 8, 9]
    without_first_and_last = x[1:-1]  # [1, 2, ..., 8]
    copy_of_x = x[:]  # [-1, 1, 2, ..., 9]
    print first_three
    print three_to_end
    print one_to_four
    print last_three
    print without_first_and_last
    print copy_of_x


# 逐个元素走，O(n)
def membership():
    _1 = 1 in [1, 2, 3]  # True
    _0 = 0 in [1, 2, 3]  # False
    print _1, _0


def concatenate():
    x = [1, 2, 3]
    x.extend([4, 5, 6])  # x is now [1,2,3,4,5,6]
    print x
    x = [1, 2, 3]
    y = x + [4, 5, 6]  # y is [1, 2, 3, 4, 5, 6]; x is unchanged
    print y
    x = [1, 2, 3]
    x.append(0)  # x is now [1, 2, 3, 0]
    print x
    y = x[-1]  # equals 0
    print y
    z = len(x)  # equals 4
    print z


def unpack():
    x, y = [1, 2]
    print x, y
    _, y = [1, 2]
    print y


if __name__ == '__main__':
    # listBase()
    # nth()
    # slice()
    # membership()
    # concatenate()
    unpack()
